<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">编辑图片</h3>
                    </div>
                    <form class="form-horizontal" id="form" action="{:url('admin/pic/postsave','','')}">
                        <input name="id" type="hidden" id="id" value="{$id}">
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">图片类型</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="type" name="type">
                                    <option value="0">请选择</option>
                                    <option value="1" {if condition="$row.type == 1"}selected{/if}>首页轮播图</option>
                                    <option value="2" {if condition="$row.type == 2"}selected{/if}>房抵贷图片</option>
                                    <option value="3" {if condition="$row.type == 3"}selected{/if}>车抵贷图片</option>
                                </select>
                                <span class="help-block" style="color:#f00;"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="img" class="col-sm-2 control-label">选择图片</label>
                            <div class="col-sm-10">
                                <input type="file" class="form-control" id="img" name="img">
                                <span class="help-block" style="color:#f00;"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">链接地址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="url" name="url" placeholder="链接地址" value="{$row.url}">
                                <span class="help-block" style="color:#f00;"></span>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<line href="__STATIC__/bootstrap-fileinput/css/fileinput.css" type="text/css" rel="stylesheet" />
<script src="__STATIC__/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="__STATIC__/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script type="text/javascript">

    var imgName = '';

    $("#img").fileinput({
        language : 'zh',
        showRemove: false,
        showUpload: true,
        showClose: false,
        showPreview: false,
        allowedFileTypes: ['image'],
        allowedFileExtensions : ['jpg', 'jpeg', 'png', 'gif'],
        uploadUrl: '{:url("admin/public/uploadimg","","")}',
        uploadExtraData: {
            'folder': 'pic',
        },
    });

    $("#img").on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        if (result.status == 1) {
            imgName = result.data;
        } else {
            showAlert('提示', result.info, null);
        }
    });
</script>

<script type="text/javascript">

    $(function(){
        $('#resetForm').click(function(){
            $('#name').val('');
        });

        $('#saveForm').click(function(){
            var id = $('#id').val();
            var type = $('#type').val();
            if (type == 0) {
                $('#type').parents('.form-group').addClass('has-error');
                $('#type').parent().find('.help-block').html('请选择图片类型');
                return false;
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'id': id,
                    'type': type,
                    'img': imgName,
                    'url': $.trim($('#url').val()),
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/pic/index','','')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#type').focus(function(){
            if ($('#type').parents('.form-group').hasClass('has-error')) {
                $('#type').parents('.form-group').removeClass('has-error');
                $('#type').parent().find('.help-block').html('');
            }
        });

        $('#img').focus(function(){
            if ($('#img').parents('.form-group').hasClass('has-error')) {
                $('#img').parents('.form-group').removeClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('');
            }
        });

    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
